package SmartMeeting.commands;

import SmartMeeting.Entity.Meeting;
import SmartMeeting.facades.MeetingSystem;

import java.util.List;

public class CreateCommand implements Command {
    private final String agent;
    private final String time;
    private final String place;
    private final List<String> participants;
    private Meeting meeting;
    private MeetingSystem meetingSystem;

    public CreateCommand(MeetingSystem meetingSystem, String agent, String time, String place, List<String> participants) {
        this.meetingSystem = meetingSystem;//通过构建函数注入meetingSystem，确保多个命令对象共享同一个meetingSystem对象
        this.agent = agent;
        this.time = time;
        this.place = place;
        this.participants = participants;
    }

    @Override
    public void execute() {
        this.meeting = meetingSystem.createMeeting(agent, time, place, participants);
    }

    @Override
    public void undo() {
        if (meeting != null) {
            System.out.println("撤销会议创建: " + meeting.getId());
            meeting = null; // 清除会议对象
        } else {
            System.out.println("没有可撤销的会议创建操作");
        }
    }

    public Meeting getCreatedMeeting() {
        return this.meeting;
    }
}
